// Copyright 2022 NullPTR. All Rights Reserved.

#pragma once

#include "CoreMinimal.h"
#include <map>
#include <string>
#include "ft2build.h"
#include FT_FREETYPE_H
#include "FRGBABitmap.h"

namespace SDFGen
{
	/**
	 * 把TTF文字轮廓渲染光栅化灰度图像
	 */
	class SDFGEN_API FTTFUtils
	{
	public:
		struct FontMetrics
		{
			float AdvanceH;
			float AdvanceV;
			FVector2D BearingH;
			FVector2D BearingV;
			float BitmapTop;
			float BitmapLeft;
		};
		
	public:
		FTTFUtils();
		~FTTFUtils();

		static void Init();
		static void Release();
		static void RenderToFontBitmap(FRGBABitmap* FontBitmap, FontMetrics* Metrics, const FString& single_char, const FString& font_path, int font_size = 4096);
		static void RenderToFontBitmap(FImage* FontBitmap, FontMetrics* Metrics, const FString& single_char, const FString& font_path, int font_size = 4096);

	private:
		inline static FT_Library FTLibrary = nullptr;
		static std::map<std::string, FT_Face> FTFaceMap;
	};
}
